﻿using ParserGenerator.Exceptions;

namespace ParserGenerator.SyntacticAnalysis
{
    partial class IntegerLiteral
    {
        public bool IsNativeInt => int.MinValue <= Value && Value <= int.MaxValue;

        public int AsNativeInt
        {
            get
            {
                if (IsNativeInt)
                    return (int)Value;
                ValueErrorException e = new ValueErrorException(SR.IntegerLiteralValueTooHugeToFit);
                e.AddLocation(Context);
                throw e;
            }
        }
    }
}
